package cn.chia.front.dao.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Component;

import cn.chia.front.dao.IOrderFrontDAO;
import cn.chia.pojo.Orderitems;
import cn.chia.pojo.Orders;
import cn.chia.utils.Onuser;

@Component
public class OrderFrontDAOImpl extends HibernateDaoSupport implements IOrderFrontDAO {

	@Autowired
	public OrderFrontDAOImpl(HibernateTemplate hibernateTemplate){
		super.setHibernateTemplate(hibernateTemplate);
	}

	public void doCreate(Orders vo) throws Exception {
		
	}

	public void doRemove(Integer id) throws Exception {
		
	}
	//修改订单
	public void doUpdate(Orders vo) throws Exception {
		super.getHibernateTemplate().update(vo);
	}
	//查询所有订单
	public List<Orders> findAll() throws Exception {
		return super.getHibernateTemplate().find("from Orders where user = '"+Onuser.user().getUserid()+"' order by id");
	}

	public List<Orders> findAll(int pageNo, int pageSize, String keyword,
			String column) throws Exception {
		return null;
	}
	//根据id查订单
	public Orders findById(Integer id) throws Exception {
		return (Orders) super.getHibernateTemplate().find("from Orders where id='"+id+"'").get(0);
	}

	public int getAllCount(String keyword, String column) throws Exception {
		return 0;
	}
	//根据订单状态差订单
	public List<?> findOrdersByState(String state) {
		return super.getHibernateTemplate().find("from Orders where state = '"+state+"' and user = '"+Onuser.user().getUserid()+"'");
	}

	public List<?> findByOrderNumber(String orderNumber) {
		return super.getHibernateTemplate().find("from Orders where orderNumber = '"+orderNumber+"' ");
	}

	public List<Orderitems> findAllOrderitems(int id) throws Exception {
		
		return (List<Orderitems>) super.getHibernateTemplate().find("from Orderitems where oid = '"+id+"'");
	}

}
